﻿using GodSystemBLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GodSystem.FormChildren
{
    public partial class FormChangePassword : Form
    {
        public FormChangePassword()
        {
            InitializeComponent();
        }

        private UsersBLL usersBLL = new UsersBLL();
        private void button_comfirm_Click(object sender, EventArgs e)
        {
            string oldPassword = textBox_old_password.Text.Trim();
            string newPassword = textBox_new_password.Text.Trim();
            string newPasswordRepeat = textBox_repeat_new_password.Text.Trim();
            if(string.IsNullOrEmpty(oldPassword) || string.IsNullOrEmpty(newPassword) || string.IsNullOrEmpty(newPasswordRepeat))
            {
                MessageBox.Show("密码不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if(newPassword.Length > 16 || newPassword.Length < 5)
            {
                MessageBox.Show("密码长度是5-16位", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!newPassword.Equals(newPasswordRepeat))
            {
                MessageBox.Show("两次新密码不一致", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            bool result = usersBLL.changePassword(oldPassword, newPassword);
            if (result)
            {
                MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return;
        }
    }
}
